package com.mini.cn.goods.io.netty.ws.info;

/**
 * Created with IntelliJ IDEA.

 * User: fly
 * Date: 2020-02-11
 * Time: 2:10 下午
 */

import com.alibaba.fastjson.annotation.JSONField;
import com.mini.cn.goods.servlet.ws.common.LCServiceConfig;
import com.mini.cn.goods.servlet.ws.common.ResponseMap;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;

import java.util.UUID;

/**
 * 这个是socket 推送消息的实体
 */
@Getter
@Setter
public class PushMessage extends FastPushMsg {

    public final static String ALLUSER = "ALL";

    //每个用户维护的消息序列号
    private int seqId;

    //消息发送人
    @NonNull
    private String from;

    //发给谁
    @JSONField(serialize = false)
    @NonNull
    private String to;

    //附加信息
    private String extra;

    //最后更新消息
    @JSONField(serialize = false)
    private long lastUpdateTime;

    //是否需要存储
    @JSONField(serialize = false)
    private boolean isRepeat;

    //对应的页面id
    private String pageId;

    //时间戳
    @NonNull
    private long timestamp;

    public static PushMessage createDuplexPushMessage(String msgSceneId, byte cmd, ResponseMap msgBody) {
        PushMessage myMessage = new PushMessage();
        myMessage.setFrom(LCServiceConfig.PUSH_FROM);
        myMessage.setMsgSceneId(msgSceneId);
        //消息流水号
        myMessage.setMsgId(UUID.randomUUID().toString());
        myMessage.setMsgBody(msgBody);
        myMessage.setCommand(cmd);
        return myMessage;
    }
}
